package com.aliyun.solutions.demo.wanxiang.web;

import org.jetbrains.annotations.NotNull;
import org.springframework.stereotype.Component;
import org.springframework.web.servlet.HandlerInterceptor;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

/**
 * 登录处理器拦截器
 *
 * @author solution
 * @date 2024/12/04
 */
@Component
public class LoginHandlerInterceptor implements HandlerInterceptor {

    @Override
    public boolean preHandle(HttpServletRequest request, @NotNull HttpServletResponse response, @NotNull Object handler)
            throws Exception {
        Boolean login = (Boolean)request.getSession(true).getAttribute("logined");
        if (login == null || !login) {
            throw new RuntimeException("未登录或登录已超时，请刷新页面后进行登录！");
        }
        return true;
    }
}
